<template>
  <el-card shadow="hover">
    <!--    查询条件部分-->
    <el-divider content-position="left"><span style="font-weight: bolder;font-size: 18px">查询条件</span></el-divider>
    <div>
      <el-form ref="showForm" label-position="right" label-width="100px">

        <el-row :gutter="24">
          <el-col :span="9">
            <el-form-item label="工资信息：">
              <el-input v-model="queryParma.gzxx" clearable size="small" placeholder="请输入查询的工资信息" />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="部门信息：">
              <el-select v-model="queryParma.bmbh" style="position: relative;left: 5px" filterable default-first-option placeholder="请选择部门信息">
                <el-option
                  key="0"
                  label=""
                  value=""
                />
                <el-option
                  v-for="item in departmentInfoList"
                  :key="item.depCode"
                  :label="item.depName"
                  :value="item.depCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="员工类型：">
              <el-select
                v-model="queryParma.yglxbh"
                style="position: relative;left: 5px"
                filterable
                default-first-option
                placeholder="请选择员工类型"
              >
                <el-option
                  key="0"
                  label=""
                  value=""
                />
                <el-option
                  v-for="item in EmpTypeList"
                  :key="item.employTypeCode"
                  :label="item.employTypeName"
                  :value="item.employTypeCode"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" align="right">
            <el-button type="primary" :loading="searchloding" @click="getSalaryInfoListPage">查询</el-button>
            <el-button @click="resetForm('showForm')">重置</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!--    查询查询部分-->
    <div>
      <el-divider content-position="left"><span style="font-weight: bolder;font-size: 18px">工资信息展示</span></el-divider>
      <!--      数据操作按钮-->
      <div style="padding: 10px" align="right">
        <el-button-group>
          <el-button type="primary" icon="el-icon-plus" @click="handleAdd">新增</el-button>
          <el-button type="danger" icon="el-icon-delete" @click="handleDeleteBatch">批量删除</el-button>
        </el-button-group>
      </div>

      <el-table
        :data="dataSource"
        :border="true"
        align="center"
        empty-text="暂无数据"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="selection"
          width="55"
          align="center"
          fixed="left"
        />
        <el-table-column
          type="index"
          :index="indexMethod"
          label="#"
          width="50"
          align="center"
          fixed="left"
        />
        <el-table-column
          label="员工昵称"
          prop="userName"
          align="center"
          width="120"
          fixed="left"
        />
        <el-table-column
          label="年龄"
          prop="employAge"
          align="center"
          width="80"
          fixed="left"
        />
        <el-table-column
          label="性别"
          prop="gender"
          align="center"
          width="80"
          fixed="left"
        />
        <el-table-column
          label="部门名称"
          width="120"
          prop="depName"
        />
        <el-table-column
          label="员工类型"
          width="120"
          prop="employTypeName"
        />
        <el-table-column
          label="基础工资"
          header-align="center"
          align="right"
          width="120"
          prop="basicSalary"
        >
          <template slot-scope="{ row }">
            <span style="color:red;font-weight: bolder">{{ row.basicSalary }}</span>  元
          </template>
        </el-table-column>
        <el-table-column
          label="综合保险"
          header-align="center"
          align="right"
          width="120"
          prop="allInsurance"
        >
          <template slot-scope="{ row }">
            <span style="color:cornflowerblue;font-weight: bolder">{{ row.allInsurance }}</span>  元
          </template>
        </el-table-column>
        <el-table-column
          label="奖金"
          header-align="center"
          align="right"
          width="120"
          prop="awardSalary"
        >
          <template slot-scope="{ row }">
            <span style="color:cornflowerblue;font-weight: bolder">{{ row.awardSalary }}</span>  元
          </template>
        </el-table-column>
        <el-table-column
          label="惩金"
          header-align="center"
          align="right"
          width="120"
          prop="finedSalary"
        >
          <template slot-scope="{ row }">
            <span style="color:orange;font-weight: bolder">{{ row.finedSalary }}</span>  元
          </template>
        </el-table-column>
        <el-table-column
          label="实际工资"
          header-align="center"
          width="120"
          align="right"
          prop="finalSalary"
        >
          <template slot-scope="{ row }">
            <span style="color:red;font-weight: bolder">{{ row.finalSalary }}</span>  元
          </template>
        </el-table-column>
        <el-table-column
          label="惩罚原因"
          width="300"
          prop="finedResion"
        />
        <el-table-column
          label="操作"
          width="200"
          fixed="right"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button>
            <el-button
              size="mini"
              type="danger"
              @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div align="center">
        <div style="display: inline-block;width: 60px;height:60px;line-height: 60px;text-align: center;font-size: 15px">
          <span style="text-align: center;line-height: 60px;width: 60px;height:60px;">共{{ dataTotals }}条</span>
        </div>
        <div style="display: inline-block">
          <el-pagination
            :current-page.sync="queryParma.pageIndex"
            :page-sizes="[5, 10, 15, 20]"
            :page-size="queryParma.pageSize"
            layout="total, sizes, prev,next, jumper"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
    <modal
      ref="modals"
      :department-info-list="departmentInfoList"
      :salary-info="modifyData"
      @reflushDataHandle="getSalaryInfoListPage"
    />
  </el-card>
</template>

<script>
import { dropBatchSalaryInfo, getAllSalaryInfoPage } from '@/api/ht/yytgl/gzgl/gzxxcx'
const { Message } = require('element-ui')
const { getAllDepartmentInfo } = require('@/api/ht/yytgl/bmgl/bmxxgl')
const { getAllEmpType } = require('@/api/ht/yytgl/yggl/yglxgl')
import Modal from '@/views/ht/yytgl/gzgl/gzxxcx/components/modal'
export default {
  name: 'Index',
  components: {
    Modal
  },
  data() {
    return {
      dataSource: [], // 信息列表
      dataTotals: 0, // 查询总条数
      modifyData: {}, // 待修改对象信息
      searchloding: false, // 搜索按钮加载
      queryParma: {
        pageIndex: 1,
        pageSize: 5,
        gzxx: '',
        yglxbh: '',
        bmbh: ''
      },
      departmentInfoList: [], // 信息数组列表集合
      EmpTypeList: [], // 员工类型数组列表集合
      hasselectedIdArray: [] // 已经选中的信息ID数组
    }
  },
  mounted() {
    this.getDepInfoListHandle() // 获取部门类型信息列表
    this.getEmpTypeListHandle() // 获取员工类型信息列表
    this.getSalaryInfoListPageHandle() // 获取工资信息
  },
  methods: {
    getDepInfoListHandle() {
      this.getDepInfoList()
    },
    getSalaryInfoListPageHandle() {
      this.getSalaryInfoListPage()
    },
    getEmpTypeListHandle() {
      this.getEmpTypeList()
    },
    async getEmpTypeList() {
      const res = await getAllEmpType()
      const data = res.data.main
      const resp = res.data.respOutMsgHeader
      if (resp.respCode === 200) {
        this.EmpTypeList = data
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    async getDepInfoList() {
      const res = await getAllDepartmentInfo()
      const data = res.data.main
      const resp = res.data.respOutMsgHeader
      if (resp.respCode === 200) {
        this.departmentInfoList = data
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    async getSalaryInfoListPage() {
      const res = await getAllSalaryInfoPage(this.queryParma)
      const data = res.data.main.dataArray
      const resp = res.data.respOutMsgHeader
      const totals = res.data.main.totalsData
      const currentPage = res.data.main.currentPage
      if (resp.respCode === 200) {
        setTimeout(() => {
          this.searchloding = false
        }, 500)
        this.dataSource = data
        this.dataTotals = totals
        this.queryParma.pageIndex = currentPage
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    indexMethod(index) {
      return index + 1 + (this.queryParma.pageIndex - 1) * this.queryParma.pageSize
    },
    handleAdd() {
      this.$refs.modals.checkModelType('add')
    },
    handleEdit(index, row) {
      // 使用父子传参方式
      this.modifyData = row
      this.$refs.modals.checkModelType('edit')
    },
    resetForm(formName) {
      // this.$refs[formName].resetFields()
      this.queryParma = {
        pageIndex: 1,
        pageSize: 5,
        gzxx: '',
        yglxbh: '',
        bmbh: ''
      }
    },
    handleDelete(index, row) {
      const rowIdarray = []
      rowIdarray.push(row.salaryCode)
      this.dropOneSalaryInfo(rowIdarray)
    },
    handleDeleteBatch() {
      this.dropBatchSalaryInfo()
    },
    async dropOneSalaryInfo(array) {
      const res = await dropBatchSalaryInfo(array)
      const resp = res.data.respOutMsgHeader
      if (resp.respCode === 200) {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
        this.getSalaryInfoListPage()
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    async dropBatchSalaryInfo() {
      const res = await dropBatchSalaryInfo(this.hasselectedIdArray)
      const resp = res.data.respOutMsgHeader
      if (resp.respCode === 200) {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
        this.getSalaryInfoListPage()
      } else {
        Message({
          message: resp.msg || 'Error',
          type: 'error',
          duration: 2 * 1000
        })
      }
    },
    handleSizeChange(val) {
      this.queryParma.pageSize = val
      this.getSalaryInfoListPage()
    },
    handleCurrentChange(val) {
      this.queryParma.pageIndex = val
      this.getSalaryInfoListPage()
    },
    handleSelectionChange(selections) {
      const rowIdArray = []
      for (const selection of selections) {
        rowIdArray.push(selection.depCode)
      }
      this.hasselectedIdArray = rowIdArray
    }
  }
}
</script>

<style scoped>

</style>
